define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'yundan/index' + location.search,
                    add_url: 'yundan/add',
                    edit_url: 'yundan/edit',
                    del_url: 'yundan/del',
                    multi_url: 'yundan/multi',
                    import_url: 'yundan/import',
                    table: 'yundan',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},


                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('费用'),
                                    title: __('费用'),
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-feiyong',
                                    icon: 'fa fa-list',
                                    url: 'yundan/feiyonglist',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.operate},




                        {field: 'admin_id', title: __('Admin_id')},
                        {field: 'chepai', title: __('Chepai'), operate: 'LIKE'},
                        {field: 'checi', title: __('Checi'), operate: 'LIKE'},
                        {field: 'start', title: __('Start'), operate: 'LIKE'},
                        {field: 'desti', title: __('Desti'), operate: 'LIKE'},
                        {field: 'huowu', title: __('Huowu'), operate: 'LIKE'},



                    ]
                ]
            });

            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".btn-editone").data("area", ["100%", "100%"]);
                $(".btn-feiyong").data("area", ["100%", "100%"]);
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        feiyonglist: function () {


            Table.api.init();
            var table_baoxian = $("#feiyongtable");
            table_baoxian.bootstrapTable({
                url: 'yundan/feiyonglist/ids/' + Config.yundanid + location.search,
                extend: {
                    index_url:'yundan/feiyonglist/ids/' + Config.yundanid + location.search,
                    add_url: 'feiyong/addfeiyong/yundanid/'+Config.yundanid,
                    edit_url: 'feiyong/edit',
                    del_url: 'feiyong/del',
                    table: 'feiyong',
                },
                toolbar: '#tb_feiyong',
                sortName: 'id', showColumns: false, showToggle: false, showExport: false, showSearch: false, commonSearch: false, search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                       /* {field: 'fayun_id', title: __('Fayun_id')},
                        {field: 'chengyun_id', title: __('Chengyun_id')},
                        {field: 'jiesuandan_id', title: __('Jiesuandan_id')},*/

                        {field: 'feiyong', title: __('Feiyong'), operate:'BETWEEN'},
                        {field: 'shuoming', title: __('说明'), operate:false},
                        {field: 'checi_id', title: __('Checi_id')},
                       /* {field: 'tijiaotime', title: __('Tijiaotime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'querentime', title: __('Querentime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},*/
                        {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                    ]
                ]
            });
            table_baoxian.on('load-success.bs.table', function (e, data) {console.log(data);$("#money").text(data.extend.money);});
            Table.api.bindevent(table_baoxian);

            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});